package dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;


/**
 * This class was autogenerated by Torque on:
 *
 * [Fri Jan 09 02:39:32 PST 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Employee
 */
public abstract class BaseEmployee extends BaseObject
{
    /** The Peer class */
    private static final EmployeePeer peer =
        new EmployeePeer();

        
    /** The value for the employeeid field */
    private int employeeid;
      
    /** The value for the employeenumber field */
    private String employeenumber;
      
    /** The value for the firstname field */
    private String firstname;
      
    /** The value for the middlename field */
    private String middlename;
      
    /** The value for the lastname field */
    private String lastname;
  
    
    /**
     * Get the Employeeid
     *
     * @return int
     */
    public int getEmployeeid()
    {
        return employeeid;
    }

                                              
    /**
     * Set the value of Employeeid
     *
     * @param v new value
     */
    public void setEmployeeid(int v) throws TorqueException
    {
    
                  if (this.employeeid != v)
              {
            this.employeeid = v;
            setModified(true);
        }
    
          
                                  
        // update associated EmployeeRank
        if (collEmployeeRanks != null)
        {
            for (int i = 0; i < collEmployeeRanks.size(); i++)
            {
                ((EmployeeRank) collEmployeeRanks.get(i))
                    .setEmployeeid(v);
            }
        }
                                          
        // update associated EmployeeUnit
        if (collEmployeeUnits != null)
        {
            for (int i = 0; i < collEmployeeUnits.size(); i++)
            {
                ((EmployeeUnit) collEmployeeUnits.get(i))
                    .setEmployeeid(v);
            }
        }
                                          
        // update associated StudentAdviser
        if (collStudentAdvisers != null)
        {
            for (int i = 0; i < collStudentAdvisers.size(); i++)
            {
                ((StudentAdviser) collStudentAdvisers.get(i))
                    .setEmployeeid(v);
            }
        }
                      }
  
    /**
     * Get the Employeenumber
     *
     * @return String
     */
    public String getEmployeenumber()
    {
        return employeenumber;
    }

                        
    /**
     * Set the value of Employeenumber
     *
     * @param v new value
     */
    public void setEmployeenumber(String v) 
    {
    
                  if (!ObjectUtils.equals(this.employeenumber, v))
              {
            this.employeenumber = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Firstname
     *
     * @return String
     */
    public String getFirstname()
    {
        return firstname;
    }

                        
    /**
     * Set the value of Firstname
     *
     * @param v new value
     */
    public void setFirstname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.firstname, v))
              {
            this.firstname = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Middlename
     *
     * @return String
     */
    public String getMiddlename()
    {
        return middlename;
    }

                        
    /**
     * Set the value of Middlename
     *
     * @param v new value
     */
    public void setMiddlename(String v) 
    {
    
                  if (!ObjectUtils.equals(this.middlename, v))
              {
            this.middlename = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Lastname
     *
     * @return String
     */
    public String getLastname()
    {
        return lastname;
    }

                        
    /**
     * Set the value of Lastname
     *
     * @param v new value
     */
    public void setLastname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.lastname, v))
              {
            this.lastname = v;
            setModified(true);
        }
    
          
              }
  
         
                                
            
    /**
     * Collection to store aggregation of collEmployeeRanks
     */
    protected List collEmployeeRanks;

    /**
     * Temporary storage of collEmployeeRanks to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initEmployeeRanks()
    {
        if (collEmployeeRanks == null)
        {
            collEmployeeRanks = new ArrayList();
        }
    }

    /**
     * Method called to associate a EmployeeRank object to this object
     * through the EmployeeRank foreign key attribute
     *
     * @param l EmployeeRank
     * @throws TorqueException
     */
    public void addEmployeeRank(EmployeeRank l) throws TorqueException
    {
        getEmployeeRanks().add(l);
        l.setEmployee((Employee) this);
    }

    /**
     * The criteria used to select the current contents of collEmployeeRanks
     */
    private Criteria lastEmployeeRanksCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getEmployeeRanks(new Criteria())
     *
     * @throws TorqueException
     */
    public List getEmployeeRanks() throws TorqueException
    {
        if (collEmployeeRanks == null)
        {
            collEmployeeRanks = getEmployeeRanks(new Criteria(10));
        }
        return collEmployeeRanks;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee has previously
     * been saved, it will retrieve related EmployeeRanks from storage.
     * If this Employee is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getEmployeeRanks(Criteria criteria) throws TorqueException
    {
        if (collEmployeeRanks == null)
        {
            if (isNew())
            {
               collEmployeeRanks = new ArrayList();
            }
            else
            {
                      criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid() );
                      collEmployeeRanks = EmployeeRankPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid());
                      if (!lastEmployeeRanksCriteria.equals(criteria))
                {
                    collEmployeeRanks = EmployeeRankPeer.doSelect(criteria);
                }
            }
        }
        lastEmployeeRanksCriteria = criteria;

        return collEmployeeRanks;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getEmployeeRanks(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getEmployeeRanks(Connection con) throws TorqueException
    {
        if (collEmployeeRanks == null)
        {
            collEmployeeRanks = getEmployeeRanks(new Criteria(10), con);
        }
        return collEmployeeRanks;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee has previously
     * been saved, it will retrieve related EmployeeRanks from storage.
     * If this Employee is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getEmployeeRanks(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collEmployeeRanks == null)
        {
            if (isNew())
            {
               collEmployeeRanks = new ArrayList();
            }
            else
            {
                       criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid());
                       collEmployeeRanks = EmployeeRankPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid());
                       if (!lastEmployeeRanksCriteria.equals(criteria))
                 {
                     collEmployeeRanks = EmployeeRankPeer.doSelect(criteria, con);
                 }
             }
         }
         lastEmployeeRanksCriteria = criteria;

         return collEmployeeRanks;
     }

                        
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee is new, it will return
     * an empty collection; or if this Employee has previously
     * been saved, it will retrieve related EmployeeRanks from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Employee.
     */
    protected List getEmployeeRanksJoinEmployee(Criteria criteria)
        throws TorqueException
    {
        if (collEmployeeRanks == null)
        {
            if (isNew())
            {
               collEmployeeRanks = new ArrayList();
            }
            else
            {
                            criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid());
                            collEmployeeRanks = EmployeeRankPeer.doSelectJoinEmployee(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid());
                        if (!lastEmployeeRanksCriteria.equals(criteria))
            {
                collEmployeeRanks = EmployeeRankPeer.doSelectJoinEmployee(criteria);
            }
        }
        lastEmployeeRanksCriteria = criteria;

        return collEmployeeRanks;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee is new, it will return
     * an empty collection; or if this Employee has previously
     * been saved, it will retrieve related EmployeeRanks from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Employee.
     */
    protected List getEmployeeRanksJoinRank(Criteria criteria)
        throws TorqueException
    {
        if (collEmployeeRanks == null)
        {
            if (isNew())
            {
               collEmployeeRanks = new ArrayList();
            }
            else
            {
                            criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid());
                            collEmployeeRanks = EmployeeRankPeer.doSelectJoinRank(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(EmployeeRankPeer.EMPLOYEEID, getEmployeeid());
                        if (!lastEmployeeRanksCriteria.equals(criteria))
            {
                collEmployeeRanks = EmployeeRankPeer.doSelectJoinRank(criteria);
            }
        }
        lastEmployeeRanksCriteria = criteria;

        return collEmployeeRanks;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collEmployeeUnits
     */
    protected List collEmployeeUnits;

    /**
     * Temporary storage of collEmployeeUnits to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initEmployeeUnits()
    {
        if (collEmployeeUnits == null)
        {
            collEmployeeUnits = new ArrayList();
        }
    }

    /**
     * Method called to associate a EmployeeUnit object to this object
     * through the EmployeeUnit foreign key attribute
     *
     * @param l EmployeeUnit
     * @throws TorqueException
     */
    public void addEmployeeUnit(EmployeeUnit l) throws TorqueException
    {
        getEmployeeUnits().add(l);
        l.setEmployee((Employee) this);
    }

    /**
     * The criteria used to select the current contents of collEmployeeUnits
     */
    private Criteria lastEmployeeUnitsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getEmployeeUnits(new Criteria())
     *
     * @throws TorqueException
     */
    public List getEmployeeUnits() throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            collEmployeeUnits = getEmployeeUnits(new Criteria(10));
        }
        return collEmployeeUnits;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     * If this Employee is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getEmployeeUnits(Criteria criteria) throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                      criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid() );
                      collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid());
                      if (!lastEmployeeUnitsCriteria.equals(criteria))
                {
                    collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria);
                }
            }
        }
        lastEmployeeUnitsCriteria = criteria;

        return collEmployeeUnits;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getEmployeeUnits(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getEmployeeUnits(Connection con) throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            collEmployeeUnits = getEmployeeUnits(new Criteria(10), con);
        }
        return collEmployeeUnits;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     * If this Employee is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getEmployeeUnits(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                       criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid());
                       collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid());
                       if (!lastEmployeeUnitsCriteria.equals(criteria))
                 {
                     collEmployeeUnits = EmployeeUnitPeer.doSelect(criteria, con);
                 }
             }
         }
         lastEmployeeUnitsCriteria = criteria;

         return collEmployeeUnits;
     }

                        
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee is new, it will return
     * an empty collection; or if this Employee has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Employee.
     */
    protected List getEmployeeUnitsJoinEmployee(Criteria criteria)
        throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                            criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid());
                            collEmployeeUnits = EmployeeUnitPeer.doSelectJoinEmployee(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid());
                        if (!lastEmployeeUnitsCriteria.equals(criteria))
            {
                collEmployeeUnits = EmployeeUnitPeer.doSelectJoinEmployee(criteria);
            }
        }
        lastEmployeeUnitsCriteria = criteria;

        return collEmployeeUnits;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee is new, it will return
     * an empty collection; or if this Employee has previously
     * been saved, it will retrieve related EmployeeUnits from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Employee.
     */
    protected List getEmployeeUnitsJoinUnit(Criteria criteria)
        throws TorqueException
    {
        if (collEmployeeUnits == null)
        {
            if (isNew())
            {
               collEmployeeUnits = new ArrayList();
            }
            else
            {
                            criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid());
                            collEmployeeUnits = EmployeeUnitPeer.doSelectJoinUnit(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(EmployeeUnitPeer.EMPLOYEEID, getEmployeeid());
                        if (!lastEmployeeUnitsCriteria.equals(criteria))
            {
                collEmployeeUnits = EmployeeUnitPeer.doSelectJoinUnit(criteria);
            }
        }
        lastEmployeeUnitsCriteria = criteria;

        return collEmployeeUnits;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collStudentAdvisers
     */
    protected List collStudentAdvisers;

    /**
     * Temporary storage of collStudentAdvisers to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initStudentAdvisers()
    {
        if (collStudentAdvisers == null)
        {
            collStudentAdvisers = new ArrayList();
        }
    }

    /**
     * Method called to associate a StudentAdviser object to this object
     * through the StudentAdviser foreign key attribute
     *
     * @param l StudentAdviser
     * @throws TorqueException
     */
    public void addStudentAdviser(StudentAdviser l) throws TorqueException
    {
        getStudentAdvisers().add(l);
        l.setEmployee((Employee) this);
    }

    /**
     * The criteria used to select the current contents of collStudentAdvisers
     */
    private Criteria lastStudentAdvisersCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getStudentAdvisers(new Criteria())
     *
     * @throws TorqueException
     */
    public List getStudentAdvisers() throws TorqueException
    {
        if (collStudentAdvisers == null)
        {
            collStudentAdvisers = getStudentAdvisers(new Criteria(10));
        }
        return collStudentAdvisers;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee has previously
     * been saved, it will retrieve related StudentAdvisers from storage.
     * If this Employee is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getStudentAdvisers(Criteria criteria) throws TorqueException
    {
        if (collStudentAdvisers == null)
        {
            if (isNew())
            {
               collStudentAdvisers = new ArrayList();
            }
            else
            {
                      criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid() );
                      collStudentAdvisers = StudentAdviserPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid());
                      if (!lastStudentAdvisersCriteria.equals(criteria))
                {
                    collStudentAdvisers = StudentAdviserPeer.doSelect(criteria);
                }
            }
        }
        lastStudentAdvisersCriteria = criteria;

        return collStudentAdvisers;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getStudentAdvisers(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getStudentAdvisers(Connection con) throws TorqueException
    {
        if (collStudentAdvisers == null)
        {
            collStudentAdvisers = getStudentAdvisers(new Criteria(10), con);
        }
        return collStudentAdvisers;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee has previously
     * been saved, it will retrieve related StudentAdvisers from storage.
     * If this Employee is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getStudentAdvisers(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collStudentAdvisers == null)
        {
            if (isNew())
            {
               collStudentAdvisers = new ArrayList();
            }
            else
            {
                       criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid());
                       collStudentAdvisers = StudentAdviserPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid());
                       if (!lastStudentAdvisersCriteria.equals(criteria))
                 {
                     collStudentAdvisers = StudentAdviserPeer.doSelect(criteria, con);
                 }
             }
         }
         lastStudentAdvisersCriteria = criteria;

         return collStudentAdvisers;
     }

                        
              
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee is new, it will return
     * an empty collection; or if this Employee has previously
     * been saved, it will retrieve related StudentAdvisers from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Employee.
     */
    protected List getStudentAdvisersJoinStudent(Criteria criteria)
        throws TorqueException
    {
        if (collStudentAdvisers == null)
        {
            if (isNew())
            {
               collStudentAdvisers = new ArrayList();
            }
            else
            {
                            criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid());
                            collStudentAdvisers = StudentAdviserPeer.doSelectJoinStudent(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid());
                        if (!lastStudentAdvisersCriteria.equals(criteria))
            {
                collStudentAdvisers = StudentAdviserPeer.doSelectJoinStudent(criteria);
            }
        }
        lastStudentAdvisersCriteria = criteria;

        return collStudentAdvisers;
    }
                  
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Employee is new, it will return
     * an empty collection; or if this Employee has previously
     * been saved, it will retrieve related StudentAdvisers from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Employee.
     */
    protected List getStudentAdvisersJoinEmployee(Criteria criteria)
        throws TorqueException
    {
        if (collStudentAdvisers == null)
        {
            if (isNew())
            {
               collStudentAdvisers = new ArrayList();
            }
            else
            {
                            criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid());
                            collStudentAdvisers = StudentAdviserPeer.doSelectJoinEmployee(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(StudentAdviserPeer.EMPLOYEEID, getEmployeeid());
                        if (!lastStudentAdvisersCriteria.equals(criteria))
            {
                collStudentAdvisers = StudentAdviserPeer.doSelectJoinEmployee(criteria);
            }
        }
        lastStudentAdvisersCriteria = criteria;

        return collStudentAdvisers;
    }
                            


          
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("Employeeid");
              fieldNames.add("Employeenumber");
              fieldNames.add("Firstname");
              fieldNames.add("Middlename");
              fieldNames.add("Lastname");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("Employeeid"))
        {
                return new Integer(getEmployeeid());
            }
          if (name.equals("Employeenumber"))
        {
                return getEmployeenumber();
            }
          if (name.equals("Firstname"))
        {
                return getFirstname();
            }
          if (name.equals("Middlename"))
        {
                return getMiddlename();
            }
          if (name.equals("Lastname"))
        {
                return getLastname();
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(EmployeePeer.EMPLOYEEID))
        {
                return new Integer(getEmployeeid());
            }
          if (name.equals(EmployeePeer.EMPLOYEENUMBER))
        {
                return getEmployeenumber();
            }
          if (name.equals(EmployeePeer.FIRSTNAME))
        {
                return getFirstname();
            }
          if (name.equals(EmployeePeer.MIDDLENAME))
        {
                return getMiddlename();
            }
          if (name.equals(EmployeePeer.LASTNAME))
        {
                return getLastname();
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getEmployeeid());
            }
              if (pos == 1)
        {
                return getEmployeenumber();
            }
              if (pos == 2)
        {
                return getFirstname();
            }
              if (pos == 3)
        {
                return getMiddlename();
            }
              if (pos == 4)
        {
                return getLastname();
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(EmployeePeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    EmployeePeer.doInsert((Employee) this, con);
                    setNew(false);
                }
                else
                {
                    EmployeePeer.doUpdate((Employee) this, con);
                }
            }

                                      
                
            if (collEmployeeRanks != null)
            {
                for (int i = 0; i < collEmployeeRanks.size(); i++)
                {
                    ((EmployeeRank) collEmployeeRanks.get(i)).save(con);
                }
            }
                                          
                
            if (collEmployeeUnits != null)
            {
                for (int i = 0; i < collEmployeeUnits.size(); i++)
                {
                    ((EmployeeUnit) collEmployeeUnits.get(i)).save(con);
                }
            }
                                          
                
            if (collStudentAdvisers != null)
            {
                for (int i = 0; i < collStudentAdvisers.size(); i++)
                {
                    ((StudentAdviser) collStudentAdvisers.get(i)).save(con);
                }
            }
                          alreadyInSave = false;
        }
      }


                          
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  employeeid ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setEmployeeid(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setEmployeeid(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getEmployeeid());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public Employee copy() throws TorqueException
    {
        return copyInto(new Employee());
    }
  
    protected Employee copyInto(Employee copyObj) throws TorqueException
    {
          copyObj.setEmployeeid(employeeid);
          copyObj.setEmployeenumber(employeenumber);
          copyObj.setFirstname(firstname);
          copyObj.setMiddlename(middlename);
          copyObj.setLastname(lastname);
  
                    copyObj.setEmployeeid(0);
                                    
                                      
                
        List v = getEmployeeRanks();
        for (int i = 0; i < v.size(); i++)
        {
            EmployeeRank obj = (EmployeeRank) v.get(i);
            copyObj.addEmployeeRank(obj.copy());
        }
                                                  
                
        v = getEmployeeUnits();
        for (int i = 0; i < v.size(); i++)
        {
            EmployeeUnit obj = (EmployeeUnit) v.get(i);
            copyObj.addEmployeeUnit(obj.copy());
        }
                                                  
                
        v = getStudentAdvisers();
        for (int i = 0; i < v.size(); i++)
        {
            StudentAdviser obj = (StudentAdviser) v.get(i);
            copyObj.addStudentAdviser(obj.copy());
        }
                    
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public EmployeePeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Employee:\n");
        str.append("Employeeid = ")
           .append(getEmployeeid())
           .append("\n");
        str.append("Employeenumber = ")
           .append(getEmployeenumber())
           .append("\n");
        str.append("Firstname = ")
           .append(getFirstname())
           .append("\n");
        str.append("Middlename = ")
           .append(getMiddlename())
           .append("\n");
        str.append("Lastname = ")
           .append(getLastname())
           .append("\n");
        return(str.toString());
    }
}
